using Share;
using System.Collections.Generic;
using UnityEngine;

namespace Tower.Object
{
    public class ObjectDynamic : ObjectState
    {
        public virtual int GetDir()
        {
            return 0;
        }
        public virtual Vector2 GetDirVector()
        {
            return Vector2.one;
        }
        public virtual void SetDir(float dir = 0)
        {
        }

        public Transform GetNodeByName(string name)
        {
            if (name == "")
                return SharpNode.transform;
            var node = GetSharpNode().FindDeepChildByName(name);
            if (node == null)
            {
                XKLog.LogError("$没有[{name}]的节点");
                return SharpNode.transform;
            }
            return node.transform;
        }


        protected override void OnPositionModiy()
        {
            UpdateSortingOrder();
        }
        protected virtual void UpdateSortingOrder()
        {

        }
        [field: SerializeField]
        public float RunSpeed { get; set; } = 4;

        [field: SerializeField]
        public float MoveSpeed { get; set; } = 1;
        public virtual string GetName()
        {
            return $"{gameObject.name}";
        }

        internal void DoDispear()
        {
            DoClear();
            DoExitGame();
        }
        public void DoClear()
        {
            foreach (var effect in m_Effects)
            {
                effect?.StopOrDestroy();
            }
            m_Effects.Clear();
            m_bDestroy = true;
        }

        List<GameObject> m_Effects = new List<GameObject>();
        // 增加特效
        public virtual void AddEffect(GameObject effect, bool bDir)
        {
            m_Effects.Add(effect);
        }


        [field: SerializeField]
        public ObjectHumen Target { get; set; }

        [field: SerializeField]
        public float Radius { get; set; } = 0.2f;
    }
}
